home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Core / Includes / PascalString.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  39.9 KB  |  1,299 lines  |  [TEXT/MPS ]

  1. // PascalString.h 
  2. // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __PASCALSTRING__
  6. #define __PASCALSTRING__
  7.  
  8. // MacApp
  9.  
  10. #ifndef __MACONDITIONALMACROS__
  11. #include "MAConditionalMacros.h"
  12. #endif
  13.  
  14. // Toolbox
  15.  
  16. #ifndef __MEMORY__
  17. #include <Memory.h>
  18. #endif
  19.  
  20. #ifndef __TYPES__
  21. #include <Types.h>
  22. #endif
  23.  
  24. #ifndef __TEXTUTILS__
  25. #include <TextUtils.h>
  26. #endif
  27.  
  28. // ANSI
  29.  
  30. #ifndef __STRING__
  31. #include <string.h>
  32. #endif
  33.  
  34. #ifndef __LIMITS__
  35. #include <Limits.h>
  36. #endif
  37.  
  38. // If Length() is defined as a macro in Types.h, undefine it
  39. // so we can have member functions with the same name
  40. #ifdef Length
  41. #undef Length
  42. #endif
  43.  
  44. // Forward declaration for all the CCharStr classes.
  45. class CCharStr;
  46. class CChar255;
  47. class CChar63;
  48. class CChar32;
  49. class CChar31;
  50. class CChar27;
  51. class CChar15;
  52. class CChar2;
  53. typedef class CCharStr *CCharStrPtr, **CCharStrHandle;
  54.  
  55. // Forward declaration for all the CPascalStr classes.
  56. class CPascalStr;
  57. class CStr255;
  58. class CStr63;
  59. class CStr32;
  60. class CStr31;
  61. class CStr27;
  62. class CStr15;
  63. class CStr2;
  64. typedef class CPascalStr *CPascalStrPtr, **CPascalStrHandle;
  65. // Leave in old style name for anyone that needs it.
  66. typedef class CPascalStr CString, *CStringPtr, **CStringHandle;
  67.  
  68. typedef const CStr255& ConstCStr255Param;
  69. typedef const CStr63& ConstCStr63Param;
  70. typedef const CStr32& ConstCStr32Param;
  71. typedef const CStr31& ConstCStr31Param;
  72. typedef const CStr27& ConstCStr27Param;
  73. typedef const CStr15& ConstCStr15Param;
  74. typedef const CStr2& ConstCStr2Param;
  75.  
  76. // Some constants defining the length of each of the CPascalStr types.
  77.  
  78. const unsigned char kStr255Len = 255;
  79. const unsigned char kStr63Len = 63;
  80. const unsigned char kStr32Len = 32;
  81. const unsigned char kStr31Len = 31;
  82. const unsigned char kStr27Len = 27;
  83. const unsigned char kStr15Len = 15;
  84. const unsigned char kStr2Len = 2;
  85. const unsigned char kLengthByte = 1;
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // MABlockMove: BlockMoveData() is fastest on PowerPC, memcpy() on 68K
  89. //----------------------------------------------------------------------------------------
  90.  
  91. #if qPowerPC
  92.     #define MABlockMove(srcPtr, destPtr, byteCount) \
  93.         ::BlockMoveData(srcPtr, destPtr, Size(byteCount))
  94. #elif UINT_MAX >= ULONG_MAX
  95.     // size_t is (usually) defined as an unsigned int. If we are compiled with 2-byte ints,
  96.     // it will be smaller than a long. We want to use memcpy because it is faster,
  97.     // but it only takes a size_t for the byte count. So we use memcpy for short
  98.     // moves, and BlockMove for the long ones. 
  99.     #define MABlockMove(srcPtr, destPtr, byteCount) \
  100.         ::memcpy(destPtr, srcPtr, size_t(byteCount))
  101. #else
  102.     void MABlockMove(const void* srcPtr, void* destPtr, long byteCount);
  103. #endif
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // MABlockMoveOverlap: BlockMoveData() is fastest on PowerPC, memmove() on 68K
  107. //----------------------------------------------------------------------------------------
  108.  
  109. #if qPowerPC
  110.     #define MABlockMoveOverlap(srcPtr, destPtr, byteCount) \
  111.         ::BlockMoveData(srcPtr, destPtr, Size(byteCount))
  112. #elif UINT_MAX >= ULONG_MAX
  113.     // size_t is (usually) defined as an unsigned int. If we are compiled with 2-byte ints,
  114.     // it will be smaller than a long. We want to use memcpy because it is faster,
  115.     // but it only takes a size_t for the byte count. So we use memcpy for short
  116.     // moves, and BlockMove for the long ones. 
  117.     #define MABlockMoveOverlap(srcPtr, destPtr, byteCount) \
  118.         ::memmove(destPtr, srcPtr, size_t(byteCount));
  119. #else
  120.     void MABlockMoveOverlap(const void* srcPtr, void* destPtr, long byteCount);
  121. #endif
  122.  
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // CCharStr: simple class to enclose a null terminated c style string.
  126. //----------------------------------------------------------------------------------------
  127. class CCharStr
  128. {
  129. public:
  130.     //
  131.     // No Constructors provided. We don't want anyone constructing this class
  132.     // directly since it has no storage. Besides, constructors and assignment operators
  133.     // are not inherited anyways.
  134.     //
  135.     void CopyFrom(const unsigned char* str, unsigned char maxLength);
  136.     // From Pascal style string with length byte at beginning
  137.  
  138.     void CopyFrom(const char* str, size_t maxLength);
  139.     // From C style string with null terminator at end
  140.  
  141.     void CopyFrom(const void* str, size_t forLength);
  142.     // From raw memory for a given length
  143.  
  144.     inline size_t Length() const
  145.     { return strlen(((const char*)this)); }
  146.  
  147.     inline Boolean IsEmpty() const
  148.     { return *((const char*)this) == 0; }
  149.  
  150.     // Character selector operator.
  151.  
  152.     inline char& operator[](size_t index)
  153.     { return ((char*)this)[index]; }
  154.  
  155.     inline char operator[](size_t index) const
  156.     { return ((const char*)this)[index]; }
  157.     
  158.     inline operator const char*() const
  159.     { return (const char*)this; }
  160.  
  161.     inline operator char*()
  162.     { return (char*)this; }
  163. };
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // CChar255:
  167. //----------------------------------------------------------------------------------------
  168. class CChar255 : public CCharStr
  169. {
  170.     enum { kMaxLength = kStr255Len };
  171.     char fStr[kMaxLength + 1];
  172.  
  173. public:
  174.     inline CChar255()
  175.     { *(char*)this = 0; }
  176.     
  177.     inline CChar255(const char* str)
  178.     { CopyFrom(str, kMaxLength); }
  179.     
  180.     inline CChar255(const unsigned char* str)
  181.     { CopyFrom(str, kMaxLength); }
  182.  
  183.     inline CChar255(const void* str, size_t maxLength)
  184.     { CopyFrom(str, maxLength); }
  185.  
  186.     inline CChar255(const CPascalStr& str)
  187.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  188.  
  189.     inline CChar255(const CStr255& str)
  190.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  191. };
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // CChar63:
  195. //----------------------------------------------------------------------------------------
  196. class CChar63 : public CCharStr
  197. {
  198.     enum { kMaxLength = kStr63Len };
  199.     char fStr[kMaxLength + 1];
  200.  
  201. public:
  202.     inline CChar63()
  203.     { *(char*)this = 0; }
  204.     
  205.     inline CChar63(const char* str)
  206.     { CopyFrom(str, kMaxLength); }
  207.     
  208.     inline CChar63(const unsigned char* str)
  209.     { CopyFrom(str, kMaxLength); }
  210.  
  211.     inline CChar63(const void* str, size_t maxLength)
  212.     { CopyFrom(str, maxLength); }
  213.  
  214.     inline CChar63(const CPascalStr& str)
  215.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  216.  
  217.     inline CChar63(const CStr63& str)
  218.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  219. };
  220.  
  221. //----------------------------------------------------------------------------------------
  222. // CChar32:
  223. //----------------------------------------------------------------------------------------
  224. class CChar32 : public CCharStr
  225. {
  226.     enum { kMaxLength = kStr32Len };
  227.     char fStr[kMaxLength + 1];
  228.  
  229. public:
  230.     inline CChar32()
  231.     { *(char*)this = 0; }
  232.     
  233.     inline CChar32(const char* str)
  234.     { CopyFrom(str, kMaxLength); }
  235.     
  236.     inline CChar32(const unsigned char* str)
  237.     { CopyFrom(str, kMaxLength); }
  238.  
  239.     inline CChar32(const void* str, size_t maxLength)
  240.     { CopyFrom(str, maxLength); }
  241.  
  242.     inline CChar32(const CPascalStr& str)
  243.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  244.  
  245.     inline CChar32(const CStr32& str)
  246.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  247. };
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // CChar31:
  251. //----------------------------------------------------------------------------------------
  252. class CChar31 : public CCharStr
  253. {
  254.     enum { kMaxLength = kStr31Len };
  255.     char fStr[kMaxLength + 1];
  256.  
  257. public:
  258.     inline CChar31()
  259.     { *(char*)this = 0; }
  260.     
  261.     inline CChar31(const char* str)
  262.     { CopyFrom(str, kMaxLength); }
  263.     
  264.     inline CChar31(const unsigned char* str)
  265.     { CopyFrom(str, kMaxLength); }
  266.  
  267.     inline CChar31(const void* str, size_t maxLength)
  268.     { CopyFrom(str, maxLength); }
  269.  
  270.     inline CChar31(const CPascalStr& str)
  271.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  272.  
  273.     inline CChar31(const CStr31& str)
  274.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  275. };
  276.  
  277.  
  278. //----------------------------------------------------------------------------------------
  279. // CChar27:
  280. //----------------------------------------------------------------------------------------
  281. class CChar27 : public CCharStr
  282. {
  283.     enum { kMaxLength = kStr27Len };
  284.     char fStr[kMaxLength + 1];
  285.  
  286. public:
  287.     inline CChar27()
  288.     { *(char*)this = 0; }
  289.     
  290.     inline CChar27(const char* str)
  291.     { CopyFrom(str, kMaxLength); }
  292.     
  293.     inline CChar27(const unsigned char* str)
  294.     { CopyFrom(str, kMaxLength); }
  295.  
  296.     inline CChar27(const void* str, size_t maxLength)
  297.     { CopyFrom(str, maxLength); }
  298.  
  299.     inline CChar27(const CPascalStr& str)
  300.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  301.  
  302.     inline CChar27(const CStr27& str)
  303.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  304. };
  305.  
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // CChar15:
  309. //----------------------------------------------------------------------------------------
  310. class CChar15 : public CCharStr
  311. {
  312.     enum { kMaxLength = kStr15Len };
  313.     char fStr[kMaxLength + 1];
  314.  
  315. public:
  316.     inline CChar15()
  317.     { *(char*)this = 0; }
  318.     
  319.     inline CChar15(const char* str)
  320.     { CopyFrom(str, kMaxLength); }
  321.     
  322.     inline CChar15(const unsigned char* str)
  323.     { CopyFrom(str, kMaxLength); }
  324.  
  325.     inline CChar15(const void* str, size_t maxLength)
  326.     { CopyFrom(str, maxLength); }
  327.  
  328.     inline CChar15(const CPascalStr& str)
  329.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  330.  
  331.     inline CChar15(const CStr15& str)
  332.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  333. };
  334.  
  335.  
  336. //----------------------------------------------------------------------------------------
  337. // CChar2:
  338. //----------------------------------------------------------------------------------------
  339. class CChar2 : public CCharStr
  340. {
  341.     enum { kMaxLength = kStr2Len };
  342.     char fStr[kMaxLength + 1];
  343.  
  344. public:
  345.     inline CChar2()
  346.     { *(char*)this = 0; }
  347.     
  348.     inline CChar2(const char* str)
  349.     { CopyFrom(str, kMaxLength); }
  350.     
  351.     inline CChar2(const unsigned char* str)
  352.     { CopyFrom(str, kMaxLength); }
  353.  
  354.     inline CChar2(const void* str, size_t maxLength)
  355.     { CopyFrom(str, maxLength); }
  356.  
  357.     inline CChar2(const CPascalStr& str)
  358.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  359.  
  360.     inline CChar2(const CStr2& str)
  361.     { CopyFrom((const unsigned char*)&str, kMaxLength); }
  362. };
  363.  
  364.  
  365. //----------------------------------------------------------------------------------------
  366. // CPascalStr: Superclass of all Pascal string compatible string classes.
  367. //----------------------------------------------------------------------------------------
  368. class CPascalStr
  369. {
  370. public:
  371.     //
  372.     // No Constructors provided. We don't want anyone constructing this class
  373.     // directly since it has no storage. Besides, constructors and assignment operators
  374.     // are not inherited anyways.
  375.     //
  376.     void CopyFrom(const unsigned char* str, unsigned char maxLength);
  377.     // From Pascal style string with length byte at beginning
  378.  
  379.     void CopyFrom(const char* str, unsigned char maxLength);
  380.     // From C style string with null terminator at end
  381.  
  382.     void CopyFrom(const void* str, unsigned char forLength);
  383.     // From raw memory for a given length
  384.  
  385.     void CopyFrom(const unsigned char* str);
  386.     // From Pascal style string with length byte at beginning
  387.     // Copies up to kStr255Len bytes, be careful
  388.  
  389.     void CopyFrom(const char* str);
  390.     // From C style string with null terminator at end
  391.     // Copies up to kStr255Len bytes, be careful
  392.  
  393. #if qPowerPC || qNeedsMC68020
  394.     inline void CopyFrom(unsigned long id)
  395.     { *((unsigned char*)this) = sizeof(id); *(unsigned long*)&((unsigned char*)this)[1] = id; }
  396. #else
  397.     void CopyFrom(unsigned long id);
  398. #endif
  399.     // From a long value directly into the string
  400.  
  401. #if qPowerPC || qNeedsMC68020
  402.     inline void CopyFrom(unsigned short num)
  403.     { *((unsigned char*)this) = sizeof(num); *(unsigned short*)&((unsigned char*)this)[1] = num; }
  404. #else
  405.     void CopyFrom(unsigned short num);
  406. #endif
  407.     // From a short value directly into the string
  408.  
  409.     inline void CopyFrom(unsigned char ch)
  410.     { *((unsigned char*)this) = sizeof(ch); ((unsigned char*)this)[1] = ch; }
  411.     // From a short value into the string
  412.  
  413.     inline void CopyFrom(const CPascalStr& str, unsigned char maxLength)
  414.     { CopyFrom((const unsigned char*)&str, maxLength); }
  415.     // From CPascalStr (Pascal) style string with length byte at beginning
  416.  
  417.     inline void CopyFrom(const CPascalStr& str)
  418.     { CopyFrom((const unsigned char*)&str); }
  419.     // From CPascalStr (Pascal) style string with length byte at beginning
  420.     // Copies up to kStr255Len bytes, be careful
  421.  
  422.     void CopyTo(unsigned char* str) const;
  423.     // Copies this string TO str with a length byte
  424.  
  425.     void CopyTo(char* str) const;
  426.     // Copies this string TO str with a null termination
  427.  
  428.     void CopyTo(void* str) const;
  429.     // Copies this string TO str without a null termination
  430.  
  431.     unsigned char GetMaxLength(unsigned char pos, unsigned char length) const;
  432.     // returns the maximum length to copy starting from pos
  433.     // for length characters OR the length of the string whichever comes first.
  434.  
  435.     //
  436.     // Character selection operator.
  437.     //
  438.     inline unsigned char& operator[](int pos)
  439.     { return ((unsigned char*)this)[pos]; }
  440.  
  441.     inline const unsigned char& operator[](int pos) const
  442.     { return ((const unsigned char*)this)[pos]; }
  443.     
  444.     //
  445.     // Basic length method, inherited by all derived classes. Returns a reference
  446.     //
  447.     inline unsigned char& Length()
  448.     { return *((unsigned char*)this); }
  449.  
  450.     inline const unsigned char& Length() const
  451.     { return *((const unsigned char*)this); }
  452.  
  453.     inline Boolean IsEmpty() const
  454.     { return !*(const unsigned char*)this; }
  455.  
  456.     inline void Empty()
  457.     { *(unsigned char*)this = 0; }
  458.  
  459.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  460.     inline operator const char*() const
  461.     { return CChar255(*this); }
  462.  
  463.     // Used to create a toolbox type Str255, etc. from our CPascalStr. This is simply a type
  464.     // coercion! Both CPascalStr and Str255, etc. are expected to be pascal-style strings.
  465.     inline operator unsigned char*()
  466.     { return (unsigned char *) this; }
  467.     
  468.     inline operator const unsigned char*() const
  469.     { return (const unsigned char *) this; }
  470.  
  471.     //------------------------------------------------------------------------------------
  472.     
  473.     // Return an ID represented as a CPascalStr to the actual ID (an unsigned long).
  474.     
  475. #if qPowerPC || qNeedsMC68020
  476.     inline unsigned long ToULong() const
  477.     { return *((unsigned long *) &(*this)[1]); } // odd pointers OK
  478. #else
  479.     unsigned long ToULong() const;
  480. #endif
  481.  
  482. #if qPowerPC || qNeedsMC68020
  483.     inline unsigned short ToUShort() const
  484.     { return *((unsigned short *) &(*this)[1]); } // odd pointers OK
  485. #else
  486.     unsigned short ToUShort() const;
  487. #endif
  488.  
  489.     // Relational operators that are inherited by all the derived CPascalStr types. Five of
  490.     // each so that literal C Strings and characters can be conveniently used for one of the
  491.     // operators as well as two of the derived classes as operators.
  492.     static short CPascalStrCompare(const CPascalStr& s1, const CPascalStr& s2);
  493.     static short CPascalStrCompare(const CPascalStr& s1, const char* s2);
  494.     static short CPascalStrCompare(const CPascalStr& s1, unsigned char ch);
  495.     static short CPascalStrCompare(const char* s1, const CPascalStr& s2);
  496.     static short CPascalStrCompare(unsigned char ch, const CPascalStr& s2);
  497.  
  498.     friend Boolean operator==(const CPascalStr& s1, const CPascalStr& s2)
  499.     { return CPascalStr::CPascalStrCompare(s1, s2) == 0; }
  500.     friend Boolean operator==(const CPascalStr& s1, const char* s2)
  501.     { return CPascalStr::CPascalStrCompare(s1, s2) == 0; }
  502.     friend Boolean operator==(const CPascalStr& s1, unsigned char ch)
  503.     { return CPascalStr::CPascalStrCompare(s1, ch) == 0; }
  504.     friend Boolean operator==(const char* s1, const CPascalStr& s2)
  505.     { return CPascalStr::CPascalStrCompare(s1, s2) == 0; }
  506.     friend Boolean operator==(unsigned char ch, const CPascalStr& s2)
  507.     { return CPascalStr::CPascalStrCompare(ch, s2) == 0; }
  508.  
  509.     friend Boolean operator!=(const CPascalStr& s1, const CPascalStr& s2)
  510.     { return CPascalStr::CPascalStrCompare(s1, s2) != 0; }
  511.     friend Boolean operator!=(const CPascalStr& s1, const char* s2)
  512.     { return CPascalStr::CPascalStrCompare(s1, s2) != 0; }
  513.     friend Boolean operator!=(const CPascalStr& s1, unsigned char ch)
  514.     { return CPascalStr::CPascalStrCompare(s1, ch) != 0; }
  515.     friend Boolean operator!=(const char* s1, const CPascalStr& s2)
  516.     { return CPascalStr::CPascalStrCompare(s1, s2) != 0; }
  517.     friend Boolean operator!=(unsigned char ch, const CPascalStr& s2)
  518.     { return CPascalStr::CPascalStrCompare(ch, s2) != 0; }
  519.  
  520.     friend Boolean operator>(const CPascalStr& s1, const CPascalStr& s2)
  521.     { return CPascalStr::CPascalStrCompare(s1, s2) > 0; }
  522.     friend Boolean operator>(const CPascalStr& s1, const char* s2)
  523.     { return CPascalStr::CPascalStrCompare(s1, s2) > 0; }
  524.     friend Boolean operator>(const CPascalStr& s1, unsigned char ch)
  525.     { return CPascalStr::CPascalStrCompare(s1, ch) > 0; }
  526.     friend Boolean operator>(const char* s1, const CPascalStr& s2)
  527.     { return CPascalStr::CPascalStrCompare(s1, s2) > 0; }
  528.     friend Boolean operator>(unsigned char ch, const CPascalStr& s2)
  529.     { return CPascalStr::CPascalStrCompare(ch, s2) > 0; }
  530.  
  531.     friend Boolean operator<(const CPascalStr& s1, const CPascalStr& s2)
  532.     { return CPascalStr::CPascalStrCompare(s1, s2) < 0; }
  533.     friend Boolean operator<(const CPascalStr& s1, const char* s2)
  534.     { return CPascalStr::CPascalStrCompare(s1, s2) < 0; }
  535.     friend Boolean operator<(const CPascalStr& s1, unsigned char ch)
  536.     { return CPascalStr::CPascalStrCompare(s1, ch) < 0; }
  537.     friend Boolean operator<(const char* s1, const CPascalStr& s2)
  538.     { return CPascalStr::CPascalStrCompare(s1, s2) < 0; }
  539.     friend Boolean operator<(unsigned char ch, const CPascalStr& s2)
  540.     { return CPascalStr::CPascalStrCompare(ch, s2) < 0; }
  541.  
  542.     friend Boolean operator>=(const CPascalStr& s1, const CPascalStr& s2)
  543.     { return CPascalStr::CPascalStrCompare(s1, s2) >= 0; }
  544.     friend Boolean operator>=(const CPascalStr& s1, const char* s2)
  545.     { return CPascalStr::CPascalStrCompare(s1, s2) >= 0; }
  546.     friend Boolean operator>=(const CPascalStr& s1, unsigned char ch)
  547.     { return CPascalStr::CPascalStrCompare(s1, ch) >= 0; }
  548.     friend Boolean operator>=(const char* s1, const CPascalStr& s2)
  549.     { return CPascalStr::CPascalStrCompare(s1, s2) >= 0; }
  550.     friend Boolean operator>=(unsigned char ch, const CPascalStr& s2)
  551.     { return CPascalStr::CPascalStrCompare(ch, s2) >= 0; }
  552.  
  553.     friend Boolean operator<=(const CPascalStr& s1, const CPascalStr& s2)
  554.     { return CPascalStr::CPascalStrCompare(s1, s2) <= 0; }
  555.     friend Boolean operator<=(const CPascalStr& s1, const char* s2)
  556.     { return CPascalStr::CPascalStrCompare(s1, s2) <= 0; }
  557.     friend Boolean operator<=(const CPascalStr& s1, unsigned char ch)
  558.     { return CPascalStr::CPascalStrCompare(s1, ch) <= 0; }
  559.     friend Boolean operator<=(const char* s1, const CPascalStr& s2)
  560.     { return CPascalStr::CPascalStrCompare(s1, s2) <= 0; }
  561.     friend Boolean operator<=(unsigned char ch, const CPascalStr& s2)
  562.     { return CPascalStr::CPascalStrCompare(ch, s2) <= 0; }
  563.  
  564.     // Concatenation operator that are inherited by all the derived CPascalStr types. Three
  565.     // of each so that literal C Strings can be conveniently used for one of the operators
  566.     // as well as using any two classes derived from CPascalStr.
  567.     friend CStr255 operator+(const CPascalStr& s1, const CPascalStr& s2);
  568.     friend CStr255 operator+(const CPascalStr& s1, const char* s2);
  569.     friend CStr255 operator+(const CPascalStr& s1, unsigned char ch);
  570.     friend CStr255 operator+(const char* s1, const CPascalStr& s2);
  571.     friend CStr255 operator+(unsigned char ch, const CPascalStr& s2);
  572.  
  573.     // Methods that mimic the Pascal builtin CPascalStr functions for Pos, Insert and Delete.
  574.     // Note that insert and copy is implemented in the derived classes.
  575.     unsigned char Pos(const char* subStr, unsigned char startPos = 1);
  576.     unsigned char Pos(const CPascalStr& subStr, unsigned char startPos = 1);
  577.     void Delete(unsigned char pos, unsigned char length);
  578.  
  579.     void Insert(const char* insStr, unsigned char insStrLength, unsigned char pos, unsigned char maxLength);
  580.     void Insert(const char* insStr, unsigned char pos, unsigned char maxLength);
  581.     void Insert(const char* insStr, unsigned char pos);
  582.     void Insert(const CPascalStr& insStr, unsigned char pos, unsigned char maxLength);
  583.     void Insert(const CPascalStr& insStr, unsigned char pos);
  584.  
  585.     
  586. //----------------------------------------------------------------------------------------
  587. // static member functions
  588. //----------------------------------------------------------------------------------------
  589.     static Handle SetItl2Handle(Handle itsItl2Handle);
  590.  
  591. //----------------------------------------------------------------------------------------
  592. // static data members
  593. //----------------------------------------------------------------------------------------
  594.     static Handle fgItl2Handle;            // Handle to the international rsrc to be used
  595.                                         // in string compares. Normally NULL, MacApp depends on
  596.                                         // The system value for proper operation of it's internal
  597.                                         // Strings, However you may replace and restore this
  598.                                         // during certain of your own operations.
  599. };
  600.  
  601.  
  602. //----------------------------------------------------------------------------------------
  603. // CStr255:
  604. //----------------------------------------------------------------------------------------
  605. class CStr255 : public CPascalStr
  606. {
  607. public:
  608.     enum { kMaxLength = kStr255Len };
  609.     Str255 fStr;
  610.  
  611. public:
  612.     inline CStr255()
  613.     { *(unsigned char*)this = 0; }
  614.     
  615.     inline CStr255(const CPascalStr& str)
  616.     { CopyFrom(str); }
  617.     // Generic string constructor
  618.     
  619.     inline CStr255(const CStr255& str)
  620.     { CopyFrom(str); }
  621.     // copy constructor
  622.  
  623.     //    
  624.     // Don't have any optimized constructors for string smaller than me.
  625.     // Because all other strings are smaller than me, so we don't need any.
  626.     //
  627.  
  628.     inline CStr255(const unsigned char* str)
  629.     { CopyFrom(str); }
  630.     
  631.     inline CStr255(const char* str)
  632.     { CopyFrom(str); }
  633.  
  634.     inline CStr255(const char* str, unsigned char maxLength)
  635.     { CopyFrom(str, maxLength); }
  636.  
  637.     inline CStr255(const void* str, unsigned char forLength)
  638.     { CopyFrom(str, forLength); }
  639.  
  640.     inline CStr255(unsigned long id)
  641.     { CopyFrom(id); }
  642.  
  643.     inline CStr255(unsigned short num)
  644.     { CopyFrom(num); }
  645.  
  646.     inline CStr255(unsigned char ch)
  647.     { CopyFrom(ch); }
  648.     
  649.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  650.     inline operator const char*() const
  651.     { return CChar255(*this); }
  652.  
  653.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  654.     
  655.     inline CStr255& Copy(unsigned char pos, unsigned char length) const
  656.     { return CStr255((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  657.  
  658.     inline void Insert(const CPascalStr& str, unsigned char pos)
  659.     { CPascalStr::Insert(str, pos); }
  660.  
  661.     inline void Insert(const char* str, unsigned char pos)
  662.     { CPascalStr::Insert(str, pos); }
  663.                        
  664.     // Concatenation operator
  665.     
  666.     inline CStr255& operator +=(const CPascalStr& str)
  667.     { Insert(str, Length() + 1); return *this; }
  668.  
  669.     inline CStr255& operator +=(const char* str)
  670.     { Insert(str, Length() + 1); return *this; }
  671.  
  672.     inline CStr255& operator +=(unsigned char ch)
  673.     { CPascalStr::Insert((const char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
  674.  
  675.     // Assignment operators
  676.     inline CStr255& operator=(const CStr255& str)
  677.     { CopyFrom(str); return *this; }
  678.  
  679.     inline CStr255& operator=(const CPascalStr& str)
  680.     { CopyFrom(str); return *this; }
  681.  
  682.     inline CStr255& operator=(const unsigned char* str)
  683.     { CopyFrom(str); return *this; }
  684.  
  685.     inline CStr255& operator=(const char* str)
  686.     { CopyFrom(str); return *this; }
  687.  
  688.     inline CStr255& operator=(unsigned char ch)
  689.     { CopyFrom(ch); return *this; }
  690. };
  691.  
  692.  
  693. //----------------------------------------------------------------------------------------
  694. // CStr63:
  695. //----------------------------------------------------------------------------------------
  696. class CStr63 : public CPascalStr
  697. {
  698. public:
  699.     enum { kMaxLength = kStr63Len };
  700.     Str63 fStr;
  701.  
  702. public:
  703.     // Constructors
  704.  
  705.     inline CStr63()
  706.     { *(unsigned char*)this = 0; }
  707.  
  708.     inline CStr63(const CPascalStr& str)
  709.     { CopyFrom(str, kMaxLength); }
  710.     // Generic string constructor
  711.  
  712.     inline CStr63(const CStr63& str)
  713.     { CopyFrom(str); }
  714.     // copy constructor
  715.     
  716.     inline CStr63(const CStr32& str)
  717.     { CopyFrom((const unsigned char*)&str); }
  718.     // Optimized constructor for string smaller than me. You don't have to have this though.
  719.     
  720.     inline CStr63(const CStr31& str)
  721.     { CopyFrom((const unsigned char*)&str); }
  722.     // Optimized constructor for string smaller than me. You don't have to have this though.
  723.     
  724.     inline CStr63(const CStr27& str)
  725.     { CopyFrom((const unsigned char*)&str); }
  726.     // Optimized constructor for string smaller than me. You don't have to have this though.
  727.     
  728.     inline CStr63(const CStr15& str)
  729.     { CopyFrom((const unsigned char*)&str); }
  730.     // Optimized constructor for string smaller than me. You don't have to have this though.
  731.     
  732.     inline CStr63(const CStr2& str)
  733.     { CopyFrom((const unsigned char*)&str); }
  734.     // Optimized constructor for string smaller than me. You don't have to have this though.
  735.     
  736.     inline CStr63(const unsigned char* str)
  737.     { CopyFrom(str, kMaxLength); }
  738.     
  739.     inline CStr63(const char* str)
  740.     { CopyFrom(str, kMaxLength); }
  741.  
  742.     inline CStr63(const char* str, unsigned char maxLength)
  743.     { CopyFrom(str, maxLength); }
  744.  
  745.     inline CStr63(const void* str, unsigned char forLength)
  746.     { CopyFrom(str, forLength); }
  747.  
  748.     inline CStr63(unsigned long id)
  749.     { CopyFrom(id); }
  750.  
  751.     inline CStr63(unsigned short num)
  752.     { CopyFrom(num); }
  753.  
  754.     inline CStr63(unsigned char ch)
  755.     { CopyFrom(ch); }
  756.     
  757.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  758.     inline operator const char*() const
  759.     { return CChar63(*this); }
  760.  
  761.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  762.  
  763.     inline CStr63 Copy(unsigned char pos, unsigned char length) const
  764.     { return CStr63((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  765.  
  766.     inline void Insert(const CPascalStr& str, unsigned char pos)
  767.     { CPascalStr::Insert(str, pos, kMaxLength); }
  768.  
  769.     inline void Insert(const char* str, unsigned char pos)
  770.     { CPascalStr::Insert(str, pos, kMaxLength); }
  771.  
  772.     // Concatenation operator
  773.     
  774.     inline CStr63& operator +=(const CPascalStr& str)
  775.     { Insert(str, Length() + 1); return *this; }
  776.  
  777.     inline CStr63& operator +=(const char* str)
  778.     { Insert(str, Length() + 1); return *this; }
  779.  
  780.     inline CStr63& operator +=(unsigned char ch)
  781.     { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
  782.  
  783.     // Assignment operators
  784.  
  785.     inline CStr63& operator=(const CStr63& str)
  786.     { CopyFrom(str); return *this; }
  787.  
  788.     inline CStr63& operator=(const CPascalStr& str)
  789.     { CopyFrom(str, kMaxLength); return *this; }
  790.  
  791.     inline CStr63& operator=(const unsigned char* str)
  792.     { CopyFrom(str, kMaxLength); return *this; }
  793.  
  794.     inline CStr63& operator=(const char* str)
  795.     { CopyFrom(str, kMaxLength); return *this; }
  796.  
  797.     inline CStr63& operator=(unsigned char ch)
  798.     { CopyFrom(ch); return *this; }
  799. };
  800.  
  801.  
  802. //----------------------------------------------------------------------------------------
  803. // CStr32:
  804. //----------------------------------------------------------------------------------------
  805. class CStr32 : public CPascalStr
  806. {
  807. public:
  808.     enum { kMaxLength = kStr32Len };
  809.     Str32 fStr;
  810.  
  811. public:
  812.     // Constructors
  813.  
  814.     inline CStr32()
  815.     { *(unsigned char*)this = 0; }
  816.     
  817.     inline CStr32(const CPascalStr& str)
  818.     { CopyFrom(str, kMaxLength); }
  819.     // Generic string constructor
  820.     
  821.     inline CStr32(const CStr32& str)
  822.     { CopyFrom(str); }
  823.     // copy constructor
  824.     
  825.     inline CStr32(const CStr31& str)
  826.     { CopyFrom((const unsigned char*)&str); }
  827.     // Optimized constructor for string smaller than me. You don't have to have this though.
  828.     
  829.     inline CStr32(const CStr27& str)
  830.     { CopyFrom((const unsigned char*)&str); }
  831.     // Optimized constructor for string smaller than me. You don't have to have this though.
  832.     
  833.     inline CStr32(const CStr15& str)
  834.     { CopyFrom((const unsigned char*)&str); }
  835.     // Optimized constructor for string smaller than me. You don't have to have this though.
  836.     
  837.     inline CStr32(const CStr2& str)
  838.     { CopyFrom((const unsigned char*)&str); }
  839.     // Optimized constructor for string smaller than me. You don't have to have this though.
  840.     
  841.     inline CStr32(const unsigned char* str)
  842.     { CopyFrom(str, kMaxLength); }
  843.     
  844.     inline CStr32(const char* str) 
  845.     { CopyFrom(str, kMaxLength); }
  846.  
  847.     inline CStr32(const char* str, unsigned char maxLength)
  848.     { CopyFrom(str, maxLength); }
  849.  
  850.     inline CStr32(const void* str, unsigned char forLength)
  851.     { CopyFrom(str, forLength); }
  852.  
  853.     inline CStr32(unsigned long id)
  854.     { CopyFrom(id); }
  855.     
  856.     inline CStr32(unsigned short num)
  857.     { CopyFrom(num); }
  858.  
  859.     inline CStr32(unsigned char ch)
  860.     { CopyFrom(ch); }
  861.     
  862.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  863.     inline operator const char*() const
  864.     { return CChar32(*this); }
  865.  
  866.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  867.     
  868.     inline CStr32 Copy(unsigned char pos, unsigned char length) const
  869.     { return CStr32((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  870.  
  871.     inline void Insert(const CPascalStr& str, unsigned char pos)
  872.     { CPascalStr::Insert(str, pos, kMaxLength); }
  873.  
  874.     inline void Insert(const char* str, unsigned char pos)
  875.     { CPascalStr::Insert(str, pos, kMaxLength); }
  876.  
  877.     // Concatenation operator
  878.     
  879.     inline CStr32& operator +=(const CPascalStr& str)
  880.     { Insert(str, Length() + 1); return *this; }
  881.  
  882.     inline CStr32& operator +=(const char* str)
  883.     { Insert(str, Length() + 1); return *this; }
  884.  
  885.     inline CStr32& operator +=(unsigned char ch)
  886.     { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
  887.  
  888.     // Assignment operators
  889.  
  890.     inline CStr32& operator=(const CStr32& str)
  891.     { CopyFrom(str); return *this; }
  892.  
  893.     inline CStr32& operator=(const CPascalStr& str)
  894.     { CopyFrom(str, kMaxLength); return *this; }
  895.  
  896.     inline CStr32& operator=(const unsigned char* str)
  897.     { CopyFrom(str, kMaxLength); return *this; }
  898.  
  899.     inline CStr32& operator=(const char* str)
  900.     { CopyFrom(str, kMaxLength); return *this; }
  901.  
  902.     inline CStr32& operator=(unsigned char ch)
  903.     { CopyFrom(ch); return *this; }
  904. };
  905.  
  906.  
  907. //----------------------------------------------------------------------------------------
  908. // CStr31:
  909. //----------------------------------------------------------------------------------------
  910. class CStr31 : public CPascalStr
  911. {
  912. public:
  913.     enum { kMaxLength = kStr31Len };
  914.     Str31 fStr;
  915.  
  916. public:
  917.     // Constructors
  918.  
  919.     inline CStr31()
  920.     { *(unsigned char*)this = 0; }
  921.     
  922.     inline CStr31(const CPascalStr& str)
  923.     { CopyFrom(str, kMaxLength); }
  924.     // Generic string constructor
  925.     
  926.     inline CStr31(const CStr31& str)
  927.     { CopyFrom(str); }
  928.     // copy constructor
  929.     
  930.     inline CStr31(const CStr27& str)
  931.     { CopyFrom((const unsigned char*)&str); }
  932.     // Optimized constructor for string smaller than me. You don't have to have this though.
  933.     
  934.     inline CStr31(const CStr15& str)
  935.     { CopyFrom((const unsigned char*)&str); }
  936.     // Optimized constructor for string smaller than me. You don't have to have this though.
  937.     
  938.     inline CStr31(const CStr2& str)
  939.     { CopyFrom((const unsigned char*)&str); }
  940.     // Optimized constructor for string smaller than me. You don't have to have this though.
  941.     
  942.     inline CStr31(const unsigned char* str)
  943.     { CopyFrom(str, kMaxLength); }
  944.     
  945.     inline CStr31(const char* str) 
  946.     { CopyFrom(str, kMaxLength); }
  947.  
  948.     inline CStr31(const char* str, unsigned char maxLength)
  949.     { CopyFrom(str, maxLength); }
  950.  
  951.     inline CStr31(const void* str, unsigned char forLength)
  952.     { CopyFrom(str, forLength); }
  953.  
  954.     inline CStr31(unsigned long id)
  955.     { CopyFrom(id); }
  956.     
  957.     inline CStr31(unsigned short num)
  958.     { CopyFrom(num); }
  959.  
  960.     inline CStr31(unsigned char ch)
  961.     { CopyFrom(ch); }
  962.     
  963.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  964.     inline operator const char*() const
  965.     { return CChar31(*this); }
  966.  
  967.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  968.     
  969.     inline CStr31 Copy(unsigned char pos, unsigned char length) const
  970.     { return CStr31((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  971.  
  972.     inline void Insert(const CPascalStr& str, unsigned char pos)
  973.     { CPascalStr::Insert(str, pos, kMaxLength); }
  974.  
  975.     inline void Insert(const char* str, unsigned char pos)
  976.     { CPascalStr::Insert(str, pos, kMaxLength); }
  977.  
  978.     // Concatenation operator
  979.     
  980.     inline CStr31& operator +=(const CPascalStr& str)
  981.     { Insert(str, Length() + 1); return *this; }
  982.  
  983.     inline CStr31& operator +=(const char* str)
  984.     { Insert(str, Length() + 1); return *this; }
  985.  
  986.     inline CStr31& operator +=(unsigned char ch)
  987.     { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
  988.  
  989.     // Assignment operators
  990.  
  991.     inline CStr31& operator=(const CStr31& str)
  992.     { CopyFrom(str); return *this; }
  993.  
  994.     inline CStr31& operator=(const CPascalStr& str)
  995.     { CopyFrom(str, kMaxLength); return *this; }
  996.  
  997.     inline CStr31& operator=(const unsigned char* str)
  998.     { CopyFrom(str, kMaxLength); return *this; }
  999.  
  1000.     inline CStr31& operator=(const char* str)
  1001.     { CopyFrom(str, kMaxLength); return *this; }
  1002.  
  1003.     inline CStr31& operator=(unsigned char ch)
  1004.     { CopyFrom(ch); return *this; }
  1005. };
  1006.  
  1007.  
  1008. //----------------------------------------------------------------------------------------
  1009. // CStr27:
  1010. //----------------------------------------------------------------------------------------
  1011. class CStr27 : public CPascalStr
  1012. {
  1013. public:
  1014.     enum { kMaxLength = kStr27Len };
  1015.     Str27 fStr;
  1016.  
  1017. public:
  1018.     // Constructors
  1019.  
  1020.     inline CStr27()
  1021.     { *(unsigned char*)this = 0; }
  1022.     
  1023.     inline CStr27(const CPascalStr& str)
  1024.     { CopyFrom(str, kMaxLength); }
  1025.     // Generic string constructor
  1026.     
  1027.     inline CStr27(const CStr27& str)
  1028.     { CopyFrom(str); }
  1029.     // copy constructor
  1030.     
  1031.     inline CStr27(const CStr15& str)
  1032.     { CopyFrom((const unsigned char*)&str); }
  1033.     // Optimized constructor for string smaller than me. You don't have to have this though.
  1034.     
  1035.     inline CStr27(const CStr2& str)
  1036.     { CopyFrom((const unsigned char*)&str); }
  1037.     // Optimized constructor for string smaller than me. You don't have to have this though.
  1038.     
  1039.     inline CStr27(const unsigned char* str)
  1040.     { CopyFrom(str, kMaxLength); }
  1041.     
  1042.     inline CStr27(const char* str) 
  1043.     { CopyFrom(str, kMaxLength); }
  1044.  
  1045.     inline CStr27(const char* str, unsigned char maxLength)
  1046.     { CopyFrom(str, maxLength); }
  1047.  
  1048.     inline CStr27(const void* str, unsigned char forLength)
  1049.     { CopyFrom(str, forLength); }
  1050.  
  1051.     inline CStr27(unsigned long id)
  1052.     { CopyFrom(id); }
  1053.     
  1054.     inline CStr27(unsigned short num)
  1055.     { CopyFrom(num); }
  1056.  
  1057.     inline CStr27(unsigned char ch)
  1058.     { CopyFrom(ch); }
  1059.     
  1060.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  1061.     inline operator const char*() const
  1062.     { return CChar27(*this); }
  1063.  
  1064.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  1065.     
  1066.     inline CStr27 Copy(unsigned char pos, unsigned char length) const
  1067.     { return CStr27((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  1068.  
  1069.     inline void Insert(const CPascalStr& str, unsigned char pos)
  1070.     { CPascalStr::Insert(str, pos, kMaxLength); }
  1071.  
  1072.     inline void Insert(const char* str, unsigned char pos)
  1073.     { CPascalStr::Insert(str, pos, kMaxLength); }
  1074.  
  1075.     // Concatenation operator
  1076.     
  1077.     inline CStr27& operator +=(const CPascalStr& str)
  1078.     { Insert(str, Length() + 1); return *this; }
  1079.  
  1080.     inline CStr27& operator +=(const char* str)
  1081.     { Insert(str, Length() + 1); return *this; }
  1082.  
  1083.     inline CStr27& operator +=(unsigned char ch)
  1084.     { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
  1085.  
  1086.     // Assignment operators
  1087.  
  1088.     inline CStr27& operator=(const CStr27& str)
  1089.     { CopyFrom(str); return *this; }
  1090.  
  1091.     inline CStr27& operator=(const CPascalStr& str)
  1092.     { CopyFrom(str, kMaxLength); return *this; }
  1093.  
  1094.     inline CStr27& operator=(const unsigned char* str)
  1095.     { CopyFrom(str, kMaxLength); return *this; }
  1096.  
  1097.     inline CStr27& operator=(const char* str)
  1098.     { CopyFrom(str, kMaxLength); return *this; }
  1099.  
  1100.     inline CStr27& operator=(unsigned char ch)
  1101.     { CopyFrom(ch); return *this; }
  1102. };
  1103.  
  1104.  
  1105. //----------------------------------------------------------------------------------------
  1106. // CStr15:
  1107. //----------------------------------------------------------------------------------------
  1108. class CStr15 : public CPascalStr
  1109. {
  1110. public:
  1111.     enum { kMaxLength = kStr15Len };
  1112.     Str15 fStr;
  1113.  
  1114. public:
  1115.     // Constructors
  1116.  
  1117.     inline CStr15()
  1118.     { *(unsigned char*)this = 0; }
  1119.     
  1120.     inline CStr15(const CPascalStr& str)
  1121.     { CopyFrom(str, kMaxLength); }
  1122.     // Generic string constructor
  1123.     
  1124.     inline CStr15(const CStr15& str)
  1125.     { CopyFrom(str); }
  1126.     // copy constructor
  1127.  
  1128.     inline CStr15(const CStr2& str)
  1129.     { CopyFrom((const unsigned char*)&str); }
  1130.     // Optimized constructor for string smaller than me. You don't have to have this though.
  1131.     
  1132.     inline CStr15(const unsigned char* str)
  1133.     { CopyFrom(str, kMaxLength); }
  1134.     
  1135.     inline CStr15(const char* str) 
  1136.     { CopyFrom(str, kMaxLength); }
  1137.  
  1138.     inline CStr15(const char* str, unsigned char maxLength)
  1139.     { CopyFrom(str, maxLength); }
  1140.  
  1141.     inline CStr15(const void* str, unsigned char forLength)
  1142.     { CopyFrom(str, forLength); }
  1143.  
  1144.     inline CStr15(unsigned long id)
  1145.     { CopyFrom(id); }
  1146.     
  1147.     inline CStr15(unsigned short num)
  1148.     { CopyFrom(num); }
  1149.  
  1150.     inline CStr15(unsigned char ch)
  1151.     { CopyFrom(ch); }
  1152.     
  1153.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  1154.     inline operator const char*() const
  1155.     { return CChar15(*this); }
  1156.  
  1157.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  1158.     
  1159.     inline CStr15 Copy(unsigned char pos, unsigned char length) const
  1160.     { return CStr15((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  1161.  
  1162.     inline void Insert(const CPascalStr& str, unsigned char pos)
  1163.     { CPascalStr::Insert(str, pos, kMaxLength); }
  1164.  
  1165.     inline void Insert(const char* str, unsigned char pos)
  1166.     { CPascalStr::Insert(str, pos, kMaxLength); }
  1167.  
  1168.     // Concatenation operator
  1169.     
  1170.     inline CStr15& operator +=(const CPascalStr& str)
  1171.     { Insert(str, Length() + 1); return *this; }
  1172.  
  1173.     inline CStr15& operator +=(const char* str)
  1174.     { Insert(str, Length() + 1); return *this; }
  1175.  
  1176.     inline CStr15& operator +=(unsigned char ch)
  1177.     { CPascalStr::Insert((char*)&ch, 1, Length() + 1, kMaxLength); return *this; }
  1178.  
  1179.     // Assignment operators
  1180.  
  1181.     inline CStr15& operator=(const CStr15& str)
  1182.     { CopyFrom(str); return *this; }
  1183.  
  1184.     inline CStr15& operator=(const CPascalStr& str)
  1185.     { CopyFrom(str, kMaxLength); return *this; }
  1186.  
  1187.     inline CStr15& operator=(const unsigned char* str)
  1188.     { CopyFrom(str, kMaxLength); return *this; }
  1189.  
  1190.     inline CStr15& operator=(const char* str)
  1191.     { CopyFrom(str, kMaxLength); return *this; }
  1192.  
  1193.     inline CStr15& operator=(unsigned char ch)
  1194.     { CopyFrom(ch); return *this; }
  1195. };
  1196.  
  1197.  
  1198. //----------------------------------------------------------------------------------------
  1199. // CStr2:
  1200. //----------------------------------------------------------------------------------------
  1201. class CStr2 : public CPascalStr
  1202. {
  1203. public:
  1204.     enum { kMaxLength = kStr2Len };
  1205.     unsigned char fStr[kStr2Len + kLengthByte];        // Str2
  1206.  
  1207. public:
  1208.     // Constructors
  1209.  
  1210.     inline CStr2()
  1211.     { *(unsigned char*)this = 0; }
  1212.     
  1213.     inline CStr2(const CPascalStr& str)
  1214.     { CopyFrom(str, kMaxLength); }
  1215.     // Generic string constructor
  1216.     
  1217.     inline CStr2(const CStr2& str)
  1218.     { CopyFrom(str); }
  1219.     // copy constructor
  1220.  
  1221.     //    
  1222.     // Don't have any optimized constructors for string smaller than me.
  1223.     // Because we haven't defined any yet. Even If you do add more CPascalStr subclasses
  1224.     // I will still work correctly, though.
  1225.     //
  1226.  
  1227.     inline CStr2(const unsigned char* str)
  1228.     { CopyFrom(str, kMaxLength); }
  1229.     
  1230.     inline CStr2(const char* str) 
  1231.     { CopyFrom(str, kMaxLength); }
  1232.  
  1233.     inline CStr2(const char* str, unsigned char maxLength)
  1234.     { CopyFrom(str, maxLength); }
  1235.  
  1236.     inline CStr2(const void* str, unsigned char forLength)
  1237.     { CopyFrom(str, forLength); }
  1238.  
  1239.     // CStr2 certainly isn't big enough for this!
  1240.     // CStr2(unsigned long id)
  1241.     // { CopyFrom(id); }
  1242.     
  1243.     inline CStr2(unsigned short num)
  1244.     { CopyFrom(num); }
  1245.  
  1246.     inline CStr2(unsigned char ch)
  1247.     { CopyFrom(ch); }
  1248.     
  1249.     // Returns a copy of the string on the stack. (as a null terminated c style string)
  1250.     inline operator const char*() const
  1251.     { return CChar2(*this); }
  1252.  
  1253.     // Copy and Insert roughly equivalent to the Pascal Insert and Copy functions.
  1254.     
  1255.     inline CStr2 Copy(unsigned char pos, unsigned char length) const
  1256.     { return CStr2((const char*)&(*this)[pos], GetMaxLength(pos, length)); }
  1257.  
  1258.     inline void Insert(const CPascalStr& str, unsigned char pos)
  1259.     { CPascalStr::Insert(str, pos, kMaxLength); }
  1260.  
  1261.     inline void Insert(const char* str, unsigned char pos)
  1262.     { CPascalStr::Insert(str, pos, kMaxLength); }
  1263.  
  1264.     // Concatenation operator
  1265.     
  1266.     inline CStr2& operator +=(const CPascalStr& str)
  1267.     { Insert(str, Length() + 1); return *this; }
  1268.  
  1269.     inline CStr2& operator +=(const char* str)
  1270.     { Insert(str, Length() + 1); return *this; }
  1271.  
  1272.     inline CStr2& operator +=(char ch)
  1273.     { CPascalStr::Insert(&ch, 1, Length() + 1, kMaxLength); return *this; }
  1274.  
  1275.     // Assignment operators
  1276.  
  1277.     inline CStr2& operator=(const CStr2& str)
  1278.     { CopyFrom(str); return *this; }
  1279.  
  1280.     inline CStr2& operator=(const CPascalStr& str)
  1281.     { CopyFrom(str, kMaxLength); return *this; }
  1282.  
  1283.     inline CStr2& operator=(const unsigned char* str)
  1284.     { CopyFrom(str, kMaxLength); return *this; }
  1285.  
  1286.     inline CStr2& operator=(const char* str)
  1287.     { CopyFrom(str, kMaxLength); return *this; }
  1288.  
  1289.     inline CStr2& operator=(unsigned char ch)
  1290.     { CopyFrom(ch); return *this; }
  1291. };
  1292.  
  1293.  
  1294. #if PRAGMA_ALIGN_SUPPORTED
  1295. #pragma options align=reset
  1296. #endif
  1297.  
  1298. #endif
  1299.